#ifndef LH_NONSTANDARD_485_DRIVE_H
#define LH_NONSTANDARD_485_DRIVE_H

#include "paramnonstandard485.h"
#include "serialportobj.h"
#include "transmissioninter.h"
#include "transmssion/battery_transmssion.h"
#include "transmssion/rete_transmision.h"
#include <QObject>
#define TB_Transmssion_  // DMK_Transmssion:传输德马克无刷直流驱动器  TB_Transmssion_:台邦滚筒电机
#ifdef DMK_Transmssion_
#include "transmssion/dmk_transmssion.h"
#endif
#ifdef TB_Transmssion_
#include "transmssion/tb_transmssion.h"
#endif

class LH_NonStandard_485_Drive : public QObject {
    Q_OBJECT
public:
    enum DriveErrorState {
        Serial_Open_Error = 0,  //串口打开错误
        Trans_Drive_Error,      //传输驱动器报警
        Shurt_Drive_error,      //卷帘门驱动器报警
    };

public:
    //    LH_NonStandard_485_Drive( QObject* parent = nullptr );
    explicit LH_NonStandard_485_Drive( QObject* parent = nullptr, const QString config_name = "./config/" );
    ~LH_NonStandard_485_Drive();
    /************传输接口************************/
    void onTransmissionControl( const TransmissionInter::TransMissionData transMissionData );
    /************传输接口************************/
    /************卷帘门接口**********************/
    void onShutterDoorControl( const TransmissionInter::TransMissionData transMissionData );
    /************卷帘门接口**********************/
    /************电池接口*****************/
    QString GET_Value( TransmissionInter::EnumBattery Enum );
    bool getFaultState( QString& result );
    short Reinterpret( char L, char H );
    int Reinterpret( char L, char H8, char H16, char H24 );
    /************电池接口*****************/

    /************参数接口*****************/
    ParamNonStandard485* getParamNonStandar();
signals:
    void sigTransmissionError( const uchar deviceAddress );
    void sigTransmissionState( const TransmissionInter::TransMissionData data );
    void sigErrorinfo( const DriveErrorState driveErrorState, const QString info );
    void sigSendData( SerialPortObj* obj, const QByteArray& data );

public slots:
    void sltOnInit();
    void sltOnTimer();
    void sltOnRecvieData( const QByteArray& data );
    void sltOnTransInterState( const TransmissionInter::TransMissionData& data );
    void sltOnTransInterError( const uchar& deviceAddress );

private:
    QString              config_name;
    SerialPortObj*       serialPort       = nullptr;
    ParamNonStandard485* paramNonStandard = nullptr;
    /********************************/
    QList< QByteArray >* writerList        = nullptr;
    QList< QByteArray >* readList          = nullptr;
    TransmissionInter*   transmissionInter = nullptr;
    /********************************/
    /**************卷帘门******************/
    ReTe_Transmision* shutterDoorInter = nullptr;
    /**************卷帘门*****************/
    /**************卷帘门*****************/
    Battery_Transmssion* batterInter = nullptr;
    /**************卷帘门*****************/

    //等待接收数据时间
    int     waiter_recevie_msec = 100;
    QTimer* timer               = nullptr;
    void    onTransInterInit();
    void onSetWaiterMsec( const QByteArray& data );
    void onSendSerialData( const QByteArray& data );
};

#endif  // LH_NONSTANDARD_485_DRIVE_H
